// import TableFilterMixin from '@/mixins/TableFilterMixin'
import { Component } from 'vue-facing-decorator'
import Render from '@/render/Render'
import toNative from '@/utils/toNative'
import TableRender from '@/render/TableRender'
import type { TableRenderColumnTypes } from '@/render/TableRender'
import type { FilterDto } from '@/render/FilterRender'
import { getSaleContract } from '@/api/deal'
import type { AnyObject } from 'ant-design-vue/es/_util/type'
import type { ProductDto } from '@/api/deal/types'
import { getKeyToEnum, ProductTypeCnEnum } from '@/const/enum'


@Component
export class SaleContractView extends TableRender {
    filterConfig() {
        return {
            deptId: {
                name: '所属分组',
                element: 'input',
            },
            saleId: {
                name: '成员',
                element: 'select',
                optionsType: 'sale'
            },
            productType: {
                name: '产品',
                element: 'select',
                options: getKeyToEnum(ProductTypeCnEnum)
            },
            companyName: {
                name: '客户名称',
                element: 'autoComplete',
                optionsType: 'company'
            },
        } as FilterDto
    }

    tableColumnConfig(){
        return [
            {
                field: 'companyName',
                title: '客户名称',
                params: {
                    path:(row) => {
                        return `/customer/${row.companyId}`
                    },
                },
                slots: {
                    default: 'toNext'
                }
            },
            {
                field: 'productTypeName',
                title: '产品名称',
            },
            {
                field: 'deptName',
                title: '所属分组',
            },
            {
                field: 'salesName',
                title: '归属商务',
            },
            {
                field: 'updateSalerTime',
                title: '开通时间',
                sortable: true
            },
            {
                field: 'amount',
                title: '累计金额',
                slots: {
                    default: 'price'
                }
            },
        ] as TableRenderColumnTypes<ProductDto>
    }

    async onLoadData(pageNum: number, pageSize: number, filter: {
        deptId: number,
        saleId: number,
        productType: number,
        companyName: string,
    }) {
        const list = await getSaleContract({
            pageNum,
            pageSize,
            sortField: 'openTime',
            sortOrder: this.sortFields[0]?.order ?? '',
            ...filter
        })
        return list
    }
    render() {
        return <>
            {super.render()}
        </>
    }
}

export default toNative<{}, {}>(SaleContractView)